
// 鼠标经过刷新按钮
function refreshMouseOver(e) {
    e = e || window.event;
    target = e.currentTarget;
    target.src = '../img/refresh_onMouseOver.png';
}

// 鼠标移出刷新按钮
function refreshMouseOut(e) {
    e = e || window.event;
    target = e.currentTarget;
    target.src = '../img/refresh_icon.png';
}

// 鼠标经过左侧箭头
function arrow_left_MouseOver(e) {
    e = e || window.event;
    target = e.currentTarget;
    target.src = '../img/arrow_left_onMouseOver.png';
}

// 鼠标移出左侧箭头
function arrow_left_MouseOut(e) {
    e = e || window.event;
    target = e.currentTarget;
    target.src = '../img/arrow_left.png';
}


// 向右箭头按钮
function arrow_right_Onclick() {
    alert('msg');
}


// 鼠标经过右侧箭头
function arrow_right_MouseOver(e) {
    e = e || window.event;
    target = e.currentTarget;
    target.src = '../img/arrow_right_onMouseOver.png';
}

// 鼠标移出右侧箭头
function arrow_right_MouseOut(e) {
    e = e || window.event;
    target = e.currentTarget;
    target.src = '../img/arrow_right.png';
}

// 鼠标移出后退箭头
function arrow_back_MouseOver(e){
    e = e || window.event;
    target = e.currentTarget;
    target.src = '../img/arrow_back_onMouseOver.png';
}

// 鼠标移出后退箭头
function arrow_back_MouseOut(e){
    e = e || window.event;
    target = e.currentTarget;
    target.src = '../img/arrow_back.png';
}


// 添加资源面板
function addElementToMiddle(req) {
    // alert(req.error_code);
    if (req.error_code == 0|| req.error_code == '0') {
        //刷新中部
        
        document.getElementById('middle').innerHTML = "";
        //底部信息标签
        let p = document.getElementById('footer_p_message');
        p.innerHTML = JSON.stringify(req);

        //顶部呈现地址
        let up_url = document.getElementById('up_url');
        GLO_DATA.up_url = up_url.value = req['dir_path'];

        console.log(req);
        //中部呈现资源面板
        let middle_div = document.getElementById('middle');
        //添加文件夹
        for (let i = 0; i < req.dir_data.dir_array.length; i++) {
            let container_middle_div = document.createElement('div');
            let container_img = document.createElement('img');
            let container_para = document.createElement('p');
            container_para.innerText = stringFormat(req.dir_data.dir_array[i]);
            container_img.src = '../img/Folder.png';
            container_para.sourcePath = req.dir_data.dir_array[i];
            container_para.className = 'container_para';
            container_img.className = 'container_Folder_img';
            container_middle_div.className = 'container_dir';
            container_middle_div.isDirectory = true;
            container_middle_div.choose = false;
            container_middle_div.onmouseover = overElementControl;
            container_middle_div.onmouseout = outElementControl;
            container_middle_div.ondblclick = doubleClickElementControl;
            middle_div.appendChild(container_middle_div);
            container_middle_div.appendChild(container_img);
            container_middle_div.appendChild(container_para);
        }
        //添加文件
        for (let i = 0; i < req.dir_data.file_array.length; i++) {
            console.log(req);
            let container_middle_div = document.createElement('div');
            let container_img = document.createElement('img');
            let container_para = document.createElement('p');
            container_para.innerText = stringFormat(req.dir_data.file_array[i]);
            container_img.src = req.dir_path + '\\' +  req.dir_data.file_array[i];
            container_para.sourcePath = req.dir_data.file_array[i];
            container_para.className = 'container_para';
            container_img.className = 'container_img';
            container_middle_div.className = 'container_file';
            container_middle_div.isDirectory = false;
            container_middle_div.choose = false;
            container_middle_div.onmouseover = overElementControl;
            container_middle_div.onmouseout = outElementControl;
            container_middle_div.ondblclick = doubleClickElementControl;
            middle_div.appendChild(container_middle_div);
            container_middle_div.appendChild(container_img);
            container_middle_div.appendChild(container_para);
        }

        // 添加到全局队列
        if (req.isMemory == false && GLO_DATA.up_url_array_bool == true) {
            if (GLO_DATA.up_url_array[GLO_DATA.up_url_array.length-1] != GLO_DATA.up_url) {
                GLO_DATA.up_url_array.push(GLO_DATA.up_url);
                GLO_DATA.up_url_array_pos = GLO_DATA.up_url_array.length - 1;
            }
        } else if (req.isMemory == false && GLO_DATA.up_url_array_bool == false) {
            if (GLO_DATA.up_url_array[GLO_DATA.up_url_array.length-1] != GLO_DATA.up_url) {
                GLO_DATA.up_url_array = new Array();
                GLO_DATA.up_url_array.push(GLO_DATA.up_url);
                GLO_DATA.up_url_array_pos = GLO_DATA.up_url_array.length - 1;
                GLO_DATA.up_url_array_bool = true;
            }
        }
        return true;
    } else {
        //添加失败复原up_url
        document.getElementById('up_url').value = GLO_DATA.up_url;
        return false;
    }
}


//中间元素鼠标悬停
function overElementControl(e) {
    e = e || window.event;
    let target = e.currentTarget;
    target.style.borderColor = "white";
}

//移出中间元素
function outElementControl(e) {
    e = e || window.event;
    let target = e.currentTarget;
    target.style.borderColor = "black";
}


function stringFormat(str){
    let num = 20
    if(str.length>num){
        return str.substring(0,num) + '...';
    }else{
        return str;
    }
}
